<template>
  <div class="home">
    <el-container>
      <el-header class="header">Header</el-header>
      <el-container>
        <el-aside class="aside">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#e85353"
            text-color="#fff"
            active-text-color="#ffd04b">
            <el-submenu index="1">
              <template slot="title">
                <span>组员管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="1-1">组员列表</el-menu-item>
                <el-menu-item index="1-2">添加列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
      <el-main>
         <el-table
          :data="tableData"
          style="width: 100%">
           <el-table-column
            prop="id"
            label="组员编号"
            width="180">
          </el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            width="180">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button @click="handleDelete(scope.row)" type="text" size="small">删除</el-button>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    </el-container>
  </div>
</template>
<script>
// @ is an alias to /src
import axios from 'axios'
export default {
  name: 'home',
  data() {
    return {
      tableData: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      axios.get('/api/list').then(res => {
        if (res.data.code === 1) {
          this.tableData = res.data.data
        } else {
          alert(res.data.msg)
        }
      })
    },
    handleDelete(row) {
      console.log(row)
      axios.post('/api/delete/member', {id: row.id}).then(res => {
        if (res.data.code === 1) {
          this.getData()
        } else {
          alert('删除失败')
        }
      })
    }
  },
  components: {
  }
}
</script>
<style lang="scss">

  .header {
    background: #e85353;
    color: #fff;
  }
  .aside, .el-aside {
    overflow: hidden !important;
  }
</style>